package com.hzxy.yiyid.web.module.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzxy.yiyid.web.common.base.BaseResult;
import com.hzxy.yiyid.web.module.controller.Dto.ArticleInfo;
import com.hzxy.yiyid.web.module.controller.Dto.ClassfyName;
import com.hzxy.yiyid.web.module.repository.MessageArticleMapper;
import com.hzxy.yiyid.web.module.repository.entity.ExigencyKnowleges;
import com.hzxy.yiyid.web.module.repository.entity.OldArticle;
import com.hzxy.yiyid.web.module.repository.entity.YongerArticle;
import com.hzxy.yiyid.web.module.service.MessageArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MessageArticleServiceImpl extends ServiceImpl<MessageArticleMapper, YongerArticle> implements MessageArticleService {

    @Autowired
    private MessageArticleMapper messageArticleMapper;

    @Override
    public BaseResult<?> getClassfyId(Integer classfyId) {

        //通过分类名称拿到分类id
//        Integer id = messageArticleMapper.getClassifyId(classfyName.getClassfyName());

        //以分类id去查询所有该分类下的资讯
        List<ExigencyKnowleges> listE;
        List<YongerArticle> listY;
        List<OldArticle> listO;
        if(classfyId ==1){
            listE = messageArticleMapper.selectAllExiById(classfyId);
            return BaseResult.success(listE);
        }else if(classfyId == 2){
            listY = messageArticleMapper.selectAllYonById(classfyId);
            return BaseResult.success(listY);
        }else{
            listO = messageArticleMapper.selectAllOldById(classfyId);
            return BaseResult.success(listO);
        }

    }



    @Override
    public BaseResult<?> getArticleDetails(Integer id, Integer scienceId) {
        ExigencyKnowleges exigencyKnowleges;
        YongerArticle yongerArticle;
        OldArticle oldArticle;

        //先通过科普id去对应的表，在通过文章id拿到详细的文章
        if(scienceId == 1){
            exigencyKnowleges = messageArticleMapper.getExigencyKnowleges(id);
            return BaseResult.success(exigencyKnowleges);
        }else if(scienceId == 2){
            yongerArticle = messageArticleMapper.getYongerArticle(id);
            return BaseResult.success(yongerArticle);
        }else {
            oldArticle = messageArticleMapper.getOldArticle(id);
            return BaseResult.success(oldArticle);
        }
    }
}
